// API配置文件
const config = {
  // 后端API基础URL
  baseUrl: 'http://localhost:8000/api',
  
  // 超时时间
  timeout: 10000,
  
  // API端点配置
  endpoints: {
    // 认证相关
    auth: {
      wxLogin: '/auth/wx_login/',
      userInfo: '/auth/userinfo/',
      tokenRefresh: '/auth/token/refresh/',
    },
    
    // 服务相关
    services: {
      appImages: '/services/app-images/',
      banners: '/services/banners/',
      categories: '/services/categories/',
      list: '/services/',
      detail: '/services/:id/',
    },
    
    // 技师相关
    technicians: {
      recommended: '/services/technicians/recommended/',
      nearby: '/accounts/location/nearby/',
      detail: '/technicians/:id/',
    },
    
    // 订单相关
    orders: {
      list: '/orders/',
      create: '/orders/create/',
      detail: '/orders/:id/',
      cancel: '/orders/:id/cancel/',
      pay: '/orders/:id/pay/',
    },
    
    // 支付相关
    payments: {
      create: '/payments/create/',
      notify: '/payments/notify/',
    },
    
    // 钱包相关
    wallet: {
      balance: '/wallet/balance/',
      withdraw: '/wallet/withdraw/',
      transactions: '/wallet/transactions/',
    },
    
    // 投诉相关
    complaints: {
      list: '/complaints/',
      create: '/complaints/create/',
      detail: '/complaints/:id/',
    },
    
    // 通知相关
    notifications: {
      list: '/notifications/',
      read: '/notifications/:id/read/',
    },
  }
};

// 获取完整URL
function getUrl(endpoint, params = {}) {
  let url = config.baseUrl + endpoint;
  
  // 替换路径参数
  Object.keys(params).forEach(key => {
    url = url.replace(`:${key}`, params[key]);
  });
  
  return url;
}

module.exports = {
  config,
  getUrl,
  baseUrl: config.baseUrl,
  endpoints: config.endpoints
};

